local skel = fk.CreateSkill {
  name = "emo__huadech",
  tags = {Skill.Limited},
}

Fk:loadTranslationTable{
  ["emo__huadech"] = "花的长河",
  [":emo__huadech"] = "限定技，出牌阶段，你可以令所有“绯花”角色各弃置任意牌，并令其下一张【杀】额外结算一次。然后你对自己造成X点虚拟伤害（X为本回合进入弃牌堆牌数）。",

  ["#emo__huadech"] = "花的长河：令“绯花”角色弃牌，并获得[杀]额外结算增益",
  ["#emo__huadech-discard"] = "花的长河：你可以弃置任意张牌",
  ["@@emo__huadech"] = "花的长河",

  ["$emo__huadech1"] = "于此绽放，直至荼蘼。",
  ["$emo__huadech2"] = "这将是……最美的花雨……",
}

skel:addEffect("active", {
  card_num = 0,
  target_num = 0,
  prompt = "#emo__huadech",
  target_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local tos = {}
    for _, pid in ipairs(player:getTableMark("emo__feihua_tar")) do
      local to = room:getPlayerById(pid)
      if to:isAlive() then
        table.insert(tos, to)
      end
    end
    if #tos > 0 then
      room:sortByAction(tos)
      room:doIndicate(player, tos)
      for _, to in ipairs(tos) do
        if not to:isNude() then
          room:askToDiscard(to, {min_num = 1, max_num = 999, include_equip = true,
            cancelable = true, skill_name = skel.name, prompt = "#emo__huadech-discard",
          })
        end
        if not to.dead then
          room:addPlayerMark(to, "@@emo__huadech", 1)
        end
      end
    end
    if player.dead then return end
    local n = 0
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          n = n + #move.moveInfo
        end
      end
      return false
    end, Player.HistoryTurn)
    if n > 0 then
      room:damage { from = player, to = player, damage = n, skillName = skel.name, isVirtualDMG = true }
    end
  end,
})

--- 下一张牌额外结算一次的延时效果
skel:addEffect(fk.CardUsing, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card.trueName == "slash" and player:getMark("@@emo__huadech") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__huadech", 0)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
})

return skel
